#include "gofgame/jumpdown/Scene.h"
#include "gofgame/jumpdown/util/objective-c.h"
#include "gofgame/jumpdown/util/HttpUtil.h"
#include "gofgame/jumpdown/layer/DialogLayer.h"

using namespace gofgame::jumpdown;
using namespace gofgame::jumpdown::util;
using namespace cocos2d::extension;
using namespace CocosDenshion;

bool Scene::init() {
	if (!CCScene::init()) {
		delete this;
		return false;
	}
	preLoadAudio();
	oc_new<UILayer>(&this->uiLayer);
	oc_new<SpriteLayer>(&this->spriteLayer);
	oc_new<BackgroundLayer>(&this->backgroundLayer);
	this->addChild(this->backgroundLayer);
	this->addChild(this->spriteLayer);
	this->addChild(this->uiLayer);
	return true;
}

void Scene::gameOver() {
	this->uiLayer->onGameOver();
	this->pauseSchedulerAndActions();
}

void Scene::preLoadAudio() {
	SimpleAudioEngine::sharedEngine()->preloadEffect("g2downdie.wav");
	SimpleAudioEngine::sharedEngine()->preloadEffect("g2fake.wav");
	SimpleAudioEngine::sharedEngine()->preloadEffect("g2nail.wav");
	SimpleAudioEngine::sharedEngine()->preloadEffect("g2normal.wav");
	SimpleAudioEngine::sharedEngine()->preloadEffect("g2spring.wav");
}

Scene::~Scene() {
}

UILayer *Scene::getUILayer() const {
	return this->uiLayer;
}

SpriteLayer *Scene::getSpriteLayer() const {
	return this->spriteLayer;
}

BackgroundLayer *Scene::getBackgroundLayer() const {
	return this->backgroundLayer;
}

void Scene::showMenuLayer() {
	DialogLayer *dl = DialogLayer::createDialogLayer();
	this->addChild(dl);
	CCDirector::sharedDirector()->pause();
}

void Scene::onHttpRequestCompleted(cocos2d::CCNode *sender, void *data) {
}